# CHECKLIST #
# optimization flags are on
# avg is in all directories
# thru is a sufficient value
# 

echo "Did you remember to update svn?"
echo "Did you make sure the program avg is in this directory?"
echo "Did you check the iteration value 'thru'?"
echo "DID YOU MAKE SURE AVG IS COMPILED ON THIS MACHINE?"
echo "DID YOU MAKE SURE ALL TEST PROGRAMS ARE COMPILED ON THIS MACHINE?"

#!/bin/sh
thru=12;
thru2=12;
iit=1;
impl=5;

while [ $iit -le $impl ]; do
if [ $iit -eq 1 ]; then
bigdir=jerasure;
fi
if [ $iit -eq 2 ]; then
bigdir=jerasure2;
fi
if [ $iit -eq 3 ]; then
bigdir=nostatic;
fi
if [ $iit -eq 4 ]; then
bigdir=static;
fi
if [ $iit -eq 5 ]; then
bigdir=split_hier
fi

echo "Beginning test on $bigdir"

`rm -rf $bigdir/table_results`
`mkdir $bigdir/table_results`
`rm -rf $bigdir/log_results`
`mkdir $bigdir/log_results`
`rm -rf $bigdir/shift_results`
`mkdir $bigdir/shift_results`
`rm -rf $bigdir/splitw8_results`
`mkdir $bigdir/splitw8_results`
`rm -rf $bigdir/region_results`
`mkdir $bigdir/region_results`

######## TABLE RESULTS SECTION ########
enum=5;
dir=$bigdir/table_results;
`echo "mult tables w: $enum through 13" > $dir/avg_mult`
`echo "" >> $dir/avg_mult`
`echo "div tables w: $enum through 13" > $dir/avg_div`
`echo "" >> $dir/avg_div`

echo "Beginning test on $bigdir tables"

while [ $enum -le 13 ]; do

enum2=1;
while [ $enum2 -le $thru ]; do
  `$bigdir/gf_basic_tester $enum multtable 100 >> $dir/tmp_results_table_w$enum`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_table_w$enum | grep "Mega Multiplies" | awk '{printf $4 "\n"}' > $dir/results_table_multiply_w$enum`
`cat $dir/tmp_results_table_w$enum | grep "Mega Divides" | awk '{printf $4 "\n"}' > $dir/results_table_divide_w$enum`

`cat $dir/results_table_multiply_w$enum | ./avg >> $dir/avg_mult`
`cat $dir/results_table_divide_w$enum | ./avg >> $dir/avg_div`

`rm $dir/tmp_results_table_w$enum`

enum=`echo $enum | awk '{printf $1+1}'`
done
`rm $dir/results_*`
echo "Finished test on $bigdir tables"


######## LOG RESULTS SECTION ########
enum=8;
dir=$bigdir/log_results;
`echo "mult log w: $enum through 26" > $dir/avg_mult`
`echo "" >> $dir/avg_mult`
`echo "div log w: $enum through 26" > $dir/avg_div`
`echo "" >> $dir/avg_div`

echo "Beginning test on $bigdir log tables"

while [ $enum -le 26 ]; do

enum2=1;
while [ $enum2 -le $thru ]; do
  `$bigdir/gf_basic_tester $enum logtable 100 >> $dir/tmp_results_log_w$enum`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_log_w$enum | grep "Mega Multiplies" | awk '{printf $4 "\n"}' > $dir/results_log_multiply_w$enum`
`cat $dir/tmp_results_log_w$enum | grep "Mega Divides" | awk '{printf $4 "\n"}' > $dir/results_log_divide_w$enum`

`cat $dir/results_log_multiply_w$enum | ./avg >> $dir/avg_mult`
`cat $dir/results_log_divide_w$enum | ./avg >> $dir/avg_div`

`rm $dir/tmp_results_log_w$enum`

enum=`echo $enum | awk '{printf $1+1}'`
done
`rm $dir/results_*`
echo "Finished test on $bigdir log tables"


######## SHIFT RESULTS SECTION ########
enum=20;
dir=$bigdir/shift_results;
`echo "mult shift w: $enum through 32" > $dir/avg_mult`
`echo "" >> $dir/avg_mult`
`echo "div shift w: $enum through 32" > $dir/avg_div`
`echo "" >> $dir/avg_div`

echo "Beginning test on $bigdir shift"

while [ $enum -le 32 ]; do

enum2=1;
while [ $enum2 -le $thru ]; do
  `$bigdir/gf_basic_tester $enum shift 50 >> $dir/tmp_results_shift_w$enum`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_shift_w$enum | grep "Mega Multiplies" | awk '{printf $4 "\n"}' > $dir/results_shift_multiply_w$enum`
  `cat $dir/tmp_results_shift_w$enum | grep "Mega Divides" | awk '{printf $4 "\n"}' > $dir/results_shift_divide_w$enum`

`cat $dir/results_shift_multiply_w$enum | ./avg >> $dir/avg_mult`
`cat $dir/results_shift_divide_w$enum | ./avg >> $dir/avg_div`

`rm $dir/tmp_results_shift_w$enum`

enum=`echo $enum | awk '{printf $1+1}'`
done
`rm $dir/results_*`
echo "Finished test on $bigdir shift"

######## SPLIT RESULTS SECTION ########
enum=32;
dir=$bigdir/splitw8_results;
`echo "mult splitw8 w: $enum" > $dir/avg_mult`
`echo "" >> $dir/avg_mult`
`echo "div splitw8 w: $enum" > $dir/avg_div`
`echo "" >> $dir/avg_div`

echo "Beginning test on $bigdir splitw8"

while [ $enum -le 32 ]; do

enum2=1;
while [ $enum2 -le $thru ]; do
  `$bigdir/gf_basic_tester $enum splitw8 100 >> $dir/tmp_results_splitw8_w$enum`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

  `cat $dir/tmp_results_splitw8_w$enum | grep "Mega Multiplies" | awk '{printf $4 "\n"}' > $dir/results_splitw8_multiply_w$enum`
  `cat $dir/tmp_results_splitw8_w$enum | grep "Mega Divides" | awk '{printf $4 "\n"}' > $dir/results_splitw8_divide_w$enum`
  `rm $dir/tmp_results_splitw8_w$enum`

`cat $dir/results_splitw8_multiply_w$enum | ./avg >> $dir/avg_mult`
`cat $dir/results_splitw8_divide_w$enum | ./avg >> $dir/avg_div`

enum=`echo $enum | awk '{printf $1+1}'`
done
`rm $dir/results_*`
echo "Finished test on $bigdir splitw8"

######## REGIONS RESULTS SECTION ########
dir=$bigdir/region_results;

echo "Beginning test on $bigdir region multiplications"

enum2=1;
while [ $enum2 -le $thru2 ]; do
  `$bigdir/gf_basic_tester 8 default 100 >> $dir/tmp_results_region_w8`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_region_w8 | grep "Megabytes of" | grep "Test 0:" | awk '{printf $3 "\n"}' > $dir/results_region_T0_w08`
`cat $dir/tmp_results_region_w8 | grep "Megabytes of" | grep "Test 1:" | awk '{printf $3 "\n"}' > $dir/results_region_T1_w08`
`cat $dir/tmp_results_region_w8 | grep "Megabytes of" | grep "Test 2:" | awk '{printf $3 "\n"}' > $dir/results_region_T2_w08`

`echo "Width 08, Tests 0-2" >> $dir/results_w08`
`echo "" >> $dir/results_w08`
`cat $dir/results_region_T0_w08 | ./avg >> $dir/results_w08`
`cat $dir/results_region_T1_w08 | ./avg >> $dir/results_w08`
`cat $dir/results_region_T2_w08 | ./avg >> $dir/results_w08`

`rm $dir/tmp_results_region_w8`
`rm $dir/results_region_T*`


enum2=1;
while [ $enum2 -le $thru2 ]; do
  `$bigdir/gf_basic_tester 16 default 100 >> $dir/tmp_results_region_w16`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_region_w16 | grep "Megabytes of" | grep "Test 0:" | awk '{printf $3 "\n"}' > $dir/results_region_T0_w16`
`cat $dir/tmp_results_region_w16 | grep "Megabytes of" | grep "Test 1:" | awk '{printf $3 "\n"}' > $dir/results_region_T1_w16`
`cat $dir/tmp_results_region_w16 | grep "Megabytes of" | grep "Test 2:" | awk '{printf $3 "\n"}' > $dir/results_region_T2_w16`

`echo "Width 16, Tests 0-2" >> $dir/results_w16`
`echo "" >> $dir/results_w16`
`cat $dir/results_region_T0_w16 | ./avg >> $dir/results_w16`
`cat $dir/results_region_T1_w16 | ./avg >> $dir/results_w16`
`cat $dir/results_region_T2_w16 | ./avg >> $dir/results_w16`

`rm $dir/tmp_results_region_w16`
`rm $dir/results_region_T*`


enum2=1;
while [ $enum2 -le $thru2 ]; do
  `$bigdir/gf_basic_tester 32 default 100 >> $dir/tmp_results_region_w32`
  enum2=`echo $enum2 | awk '{printf $1+1}'`
done

`cat $dir/tmp_results_region_w32 | grep "Megabytes of" | grep "Test 0:" | awk '{printf $3 "\n"}' > $dir/results_region_T0_w32`
`cat $dir/tmp_results_region_w32 | grep "Megabytes of" | grep "Test 1:" | awk '{printf $3 "\n"}' > $dir/results_region_T1_w32`
`cat $dir/tmp_results_region_w32 | grep "Megabytes of" | grep "Test 2:" | awk '{printf $3 "\n"}' > $dir/results_region_T2_w32`

`echo "Width 32, Tests 0-2" >> $dir/results_w32`
`echo "" >> $dir/results_w32`
`cat $dir/results_region_T0_w32 | ./avg >> $dir/results_w32`
`cat $dir/results_region_T1_w32 | ./avg >> $dir/results_w32`
`cat $dir/results_region_T2_w32 | ./avg >> $dir/results_w32`

`rm $dir/tmp_results_region_w32`
`rm $dir/results_region_T*`

echo "Finished test on $bigdir region multiplication"
echo "Finished all tests on $bigdir"

iit=`echo $iit | awk '{printf $1 + 1}'`
done

echo "Finished"

`make clean`
